package com.msb.mall.producet.controller;

import java.util.Arrays;
import java.util.Map;

import com.msb.mall.producet.vo.AttrResponseVO;
import com.msb.mall.producet.vo.AttrVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.msb.mall.producet.entity.AttrEntity;
import com.msb.mall.producet.service.AttrService;
import com.msb.common.utils.PageUtils;
import com.msb.common.utils.R;



/**
 * 商品属性
 *
 * @author zhangjiajun
 * @email 1606516025@qq.com
 * @date 2025-05-08 21:19:06
 */
@RestController
@RequestMapping("product/attr")
public class AttrController {
    @Autowired
    private AttrService attrService;


    /**
     * product/attr/base/list/166?t=1752489305751&page=1&limit=10&key=qqqq
     * product/attr/sale/list/166?t=1752489305751&page=1&limit=10&key=qqqq
     * @param params
     * @return
     */
    @RequestMapping("/{attrType}/list/{catelogId}")
    public R baseList(@RequestParam Map<String, Object> params,
                      @PathVariable("catelogId") Long catelogId,
                      @PathVariable("attrType") String attrType){
        PageUtils page = attrService.queryBasePage(params, catelogId, attrType);

        return R.ok().put("page", page);
    }

    /**
     *
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = attrService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{attrId}")
    public R info(@PathVariable("attrId") Long attrId){
//		AttrEntity attr = attrService.getById(attrId);
        AttrResponseVO responseVO = attrService.getAttrInfo(attrId);

        return R.ok().put("attr", responseVO);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody AttrVO vo){
//		attrService.save(attr);
        attrService.saveAttr(vo);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody AttrVO attr){
//		attrService.updateById(attr);
        attrService.updateBaseAttr(attr);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Long[] attrIds){
        //
		//attrService.removeByIds(Arrays.asList(attrIds));
        attrService.removeByIdsDeatils(attrIds);

        return R.ok();
    }

}
